

/*
This is a UI file (.ui.qml) that is intended to be edited in Qt Design Studio only.
It is supposed to be strictly declarative and only uses a subset of QML. If you edit
this file manually, you might introduce QML code that is not supported by Qt Design Studio.
Check out https://doc.qt.io/qtcreator/creator-quick-ui-forms.html for details on .ui.qml files.
*/
import QtQuick 2.15
import QtQuick.Controls 2.15

Button {
    id: control
    width:  Math.max(_Date.contentWidth,_Time.contentWidth)+20
    height: 60

    leftPadding: 20
    rightPadding: 20

    text: ""
    topPadding: 4

    background: buttonBackground
    Rectangle {
        id: buttonBackground
        color: "#00000000"
        implicitWidth: 60
        implicitHeight: 40
        opacity: enabled ? 1 : 0.3
        radius: 5
        border.color: "#00000000"
        border.width: 0
    }

    Column {
        id: column
        Text {
            id: _Time
            text: qsTr("12:00:00")
            font.pixelSize: 18
            anchors.horizontalCenter: parent.horizontalCenter
        }

        Text {
            id: _Date
            text: qsTr("2022/06/10")
            font.pixelSize: 18
            anchors.horizontalCenter: parent.horizontalCenter
        }
    }


    //当前日期时间
    function currentDateTime(){
        return Qt.formatDateTime(new Date(), "yyyy-MM-dd hh:mm:ss.zzz ddd");
    }
    function currentDate(){
        return Qt.formatDateTime(new Date(), "yyyy/MM/dd");
    }
    function currentTime(){
        return Qt.formatDateTime(new Date(), "hh:mm:ss");
    }
    //定时器
    Timer{
        id: timer
        running: true
        interval: 1 //间隔(单位毫秒):1000毫秒=1秒
        repeat: true //重复
        onTriggered:{
//            textDateTime.text = currentDateTime();
            _Date.text = currentDate()
            _Time.text = currentTime()
//            console.log(currentDateTime() )
        }
    }

    states: [
        State {
            name: "normal"
            when: !control.down

            PropertyChanges {
                target: buttonBackground
                color: "#00000000"
                border.color: "#047eff"
            }
        },
        State {
            name: "down"
            when: control.down

            PropertyChanges {
                target: buttonBackground
                color: "#047eff"
            }

            PropertyChanges {
                target: control
                display: AbstractButton.TextOnly
            }
        }
    ]
}

/*##^##
Designer {
    D{i:0;height:60;width:130}
}
##^##*/

